<?php
/**
 * Form Validation messeges helper
 *
 * Used to prepare validation error messages for Json Encoding
 * 
 * @package    FireFeed
 * @subpackage FireFeed.Form
 */
class FireFeed_Form_MyMessages 
{
    /**
     * Get validation form messages and create an arry containig these messages
     * associated to the relative localized element's label
     *  
     * @param $form Zend_Form
     * @return array of localized messages
     */
	public static function getMessages($form) 
    {
        $translate = Zend_Registry::get('Zend_Translate');
        $messages = array();
        foreach ($form->getMessages() as $elem => $err) {
            $label = $translate->translate($form->getElement($elem)->getLabel());
                foreach ($err as $type => $msg) {
                    $message = array($label => $msg);
                    $messages = array_merge($messages, $message);
                }
        }

        return $messages;
    }
}
